﻿using Analyzer;
using ClassLibrary;
using News;
using Product;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using User;

namespace Manager
{
    public partial class FrmManagerMenu : Form
    {
        public FrmManagerMenu()
        {
            InitializeComponent();
            //為了要控制滑鼠移進去時，按鈕的邊框

            //foreach (Control x in PnlManagerMenu.Controls)
            //{
            //    if (x is Button)
            //    {
            //        x.MouseMove += x_MouseMove;
            //        x.MouseLeave +=x_MouseLeave;
            //    }
            //}
        }

        private void FrmManagerMenu_Load(object sender, EventArgs e)
        {
            FrmManagerLogin frm = new FrmManagerLogin();
            frm.ShowDialog();
            if (login.level > 2)
            {
                //TODO:Application.Exit();按CLOSE方便修改程式

            }
            else
            {
                PicManager.Image = ClsImage.binaryToImage(buf);
            }
        }

        #region 變數宣告

        public static byte[] buf;//暫存二元登入者圖
        int currX, currY;//視窗移動
        bool isFrmMove = false;//視窗移動
        bool checkPic = true;//解決關閉讀圖Bug

        #endregion 

        #region 按鈕的邊框

        //private void x_MouseLeave(object sender, EventArgs e)
        //{
        //    ((Button)sender).FlatAppearance.BorderSize = 0;
        //}

        //void x_MouseMove(object sender, MouseEventArgs e)
        //{
        //    ((Button)sender).FlatAppearance.BorderSize = 1;
        //}
        private void btnManagerControl_MouseMove(object sender, MouseEventArgs e)
        {
            this.btnManagerControl.BackgroundImage = this.btnList.Images[1];
        }

        private void btnManagerControl_MouseLeave(object sender, EventArgs e)
        {
            this.btnManagerControl.BackgroundImage = this.btnList.Images[0];
        }

        private void btnNewsControl_MouseLeave(object sender, EventArgs e)
        {
            this.btnNewsControl.BackgroundImage = this.btnList.Images[2];
        }

        private void btnNewsControl_MouseMove(object sender, MouseEventArgs e)
        {
            this.btnNewsControl.BackgroundImage = this.btnList.Images[3];
        }

        private void btnProductControl_MouseLeave(object sender, EventArgs e)
        {
            this.btnProductControl.BackgroundImage = this.btnList.Images[4];
        }

        private void btnProductControl_MouseMove(object sender, MouseEventArgs e)
        {
            this.btnProductControl.BackgroundImage = this.btnList.Images[5];
        }

        private void btnUnboxingControl_MouseLeave(object sender, EventArgs e)
        {
            this.btnUnboxingControl.BackgroundImage = this.btnList.Images[6];
        }

        private void btnUnboxingControl_MouseMove(object sender, MouseEventArgs e)
        {
            this.btnUnboxingControl.BackgroundImage = this.btnList.Images[7];
        }

        private void btnUserControl_MouseLeave(object sender, EventArgs e)
        {
            this.btnUserControl.BackgroundImage = this.btnList.Images[8];
        }

        private void btnUserControl_MouseMove(object sender, MouseEventArgs e)
        {
            this.btnUserControl.BackgroundImage = this.btnList.Images[9];
        }

        private void btnMessageContol_MouseLeave(object sender, EventArgs e)
        {
            this.btnMessageContol.BackgroundImage = this.btnList.Images[10];
        }

        private void btnMessageContol_MouseMove(object sender, MouseEventArgs e)
        {
            this.btnMessageContol.BackgroundImage = this.btnList.Images[11];
        }

        private void btnAnalyzerControl_MouseLeave(object sender, EventArgs e)
        {
            this.btnAnalyzerControl.BackgroundImage = this.btnList.Images[12];
        }

        private void btnAnalyzerControl_MouseMove(object sender, MouseEventArgs e)
        {
            this.btnAnalyzerControl.BackgroundImage = this.btnList.Images[13];
        }

        #endregion

        #region 視窗移動

        #region 管理者圖

        private void pic01_MouseDown(object sender, MouseEventArgs e)
        {//紀錄位置
            if (e.Button == System.Windows.Forms.MouseButtons.Left)
            {
                this.currX = e.X;
                this.currY = e.Y;
                this.isFrmMove = true;
            }
        }

        private void pic01_MouseMove(object sender, MouseEventArgs e)
        {//運算滑鼠移動距離設定新位置
            if (this.isFrmMove)
            {
                this.Location = new Point
                    (this.Left + e.X - this.currX, this.Top + e.Y - this.currY);
            }
        }

        private void pic01_MouseUp(object sender, MouseEventArgs e)
        {//結束移動
            this.isFrmMove = false;
        }

        #endregion 

        #region bar設定

        private void bar01_MouseMove(object sender, MouseEventArgs e)
        {
            if (this.isFrmMove)
            {
                this.Location = new Point
                    (this.Left + e.X - this.currX, this.Top + e.Y - this.currY);
            }
        }

        private void bar01_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == System.Windows.Forms.MouseButtons.Left)
            {
                this.currX = e.X;
                this.currY = e.Y;
                this.isFrmMove = true;
            }
        }

        private void bar01_MouseUp(object sender, MouseEventArgs e)
        {
            this.isFrmMove = false;
        }

        #endregion

        #endregion

        #region Menu

        //--------------------------
        public void TagClear()
        {
            b1.Tag = "";
            b2.Tag = "";
            b3.Tag = "";
            b4.Tag = "";
            b5.Tag = "";
            b6.Tag = "";
            b7.Tag = "";
            return;
        }
        //----------------------------
        FrmManagerControl b1 = new FrmManagerControl();
        private void btnManagerControl_Click(object sender, EventArgs e)
        {
            this.Cursor = Cursors.AppStarting;
            if (login.level > 1)
            {
                MessageBox.Show("權限不足,請用經理或管理者登入");
            }
            else
            {
                try
                {
                    //============================================
                    if (b1.Visible == false)
                    {
                        b1.Visible = true;
                        TagClear();
                        b1.Tag = "TOP";
                    }
                    else
                    {
                        if (Convert.ToString(b1.Tag) == "TOP")
                        {
                            b1.Visible = false;
                            b1.Tag = "";
                        }
                        else
                        {
                            b1.Activate();
                            TagClear();
                            b1.Tag = "TOP";
                        }
                    }
                    //============================================
                    //b1.Visible = !b1.Visible;
                }
                catch
                {
                    b1 = new FrmManagerControl();
                    b1.Show();
                }
            }
            this.Cursor = Cursors.Default;
        }

        FrmNewsControl b2 = new FrmNewsControl();
        private void btnNewsControl_Click(object sender, EventArgs e)
        {
            this.Cursor = Cursors.AppStarting;
            try
            {
                //============================================
                if (b2.Visible == false)
                {
                    b2.Visible = true;
                    TagClear();
                    b2.Tag = "TOP";
                }
                else
                {
                    if (Convert.ToString(b2.Tag)== "TOP")
                    {
                        b2.Visible = false;
                        b2.Tag = "";
                    }
                    else
                    {
                        b2.Activate();
                        TagClear();
                        b2.Tag = "TOP";
                    }
                }
                //============================================
                //b2.Visible = !b2.Visible;
            }
            catch
            {
                b2 = new FrmNewsControl();
                b2.Show();
            }
            this.Cursor = Cursors.Default;
        }

        FrmProductsControl b3 = new FrmProductsControl();
        private void btnProductControl_Click(object sender, EventArgs e)
        {
            this.Cursor = Cursors.AppStarting;
            try
            {
                //============================================
                if (b3.Visible == false)
                {
                    b3.Visible = true;
                    TagClear();
                    b3.Tag = "TOP";
                }
                else
                {
                    if (Convert.ToString(b3.Tag) == "TOP")
                    {
                        b3.Visible = false;
                        b3.Tag = "";
                    }
                    else
                    {
                        b3.Activate();
                        TagClear();
                        b3.Tag = "TOP";
                    }
                }
                //============================================
                //b3.Visible = !b3.Visible;
            }
            catch
            {
                b3 = new FrmProductsControl();
                b3.Show();
            }
            this.Cursor = Cursors.Default;
        }

        FrmUnboxing_article b4 = new FrmUnboxing_article();
        private void btnUnboxingControl_Click(object sender, EventArgs e)
        {
            this.Cursor = Cursors.AppStarting;
            try
            {
                //============================================
                if (b4.Visible == false)
                {
                    b4.Visible = true;
                    TagClear();
                    b4.Tag = "TOP";
                }
                else
                {
                    if (Convert.ToString(b4.Tag)== "TOP")
                    {
                        b4.Visible = false;
                        b4.Tag = "";
                    }
                    else
                    {
                        b4.Activate();
                        TagClear();
                        b4.Tag = "TOP";
                    }
                }
                //============================================
                //b4.Visible = !b4.Visible;
            }
            catch
            {
                b4 = new FrmUnboxing_article();
                b4.Show();
            }
            this.Cursor = Cursors.Default;

        }

        FrmUserControl b5 = new FrmUserControl();
        private void btnUserControl_Click(object sender, EventArgs e)
        {
            this.Cursor = Cursors.AppStarting;
            try
            {
                //============================================
                if (b5.Visible == false)
                {
                    b5.Visible = true;
                    TagClear();
                    b5.Tag = "TOP";
                }
                else
                {
                    if (Convert.ToString(b5.Tag) == "TOP")
                    {
                        b5.Visible = false;
                        b5.Tag = "";
                    }
                    else
                    {
                        b5.Activate();
                        TagClear();
                        b5.Tag = "TOP";
                    }
                }
                //============================================
                //b5.Visible = !b5.Visible;
            }
            catch
            {
                b5 = new FrmUserControl();
                b5.Show();
            }
            this.Cursor = Cursors.Default;

        }

        FrmMessageControl b6 = new FrmMessageControl();
        private void btnMessageContol_Click(object sender, EventArgs e)
        {
            this.Cursor = Cursors.AppStarting;
            try
            {
                //============================================
                if (b6.Visible == false)
                {
                    b6.Visible = true;
                    TagClear();
                    b6.Tag = "TOP";
                }
                else
                {
                    if (Convert.ToString(b6.Tag)== "TOP")
                    {
                        b6.Visible = false;
                        b6.Tag = "";
                    }
                    else
                    {
                        b6.Activate();
                        TagClear();
                        b6.Tag = "TOP";
                    }
                }
                //============================================
                //b6.Visible = !b6.Visible;
            }
            catch
            {
                b6 = new FrmMessageControl();
                b6.Show();
            }
            this.Cursor = Cursors.Default;

        }

        FrmAnalyzerList b7 = new FrmAnalyzerList();
        private void btnAnalyzerControl_Click(object sender, EventArgs e)
        {
            this.Cursor = Cursors.AppStarting;
            try
            {
                //============================================
                if (b7.Visible == false)
                {
                    b7.Visible = true;
                    TagClear();
                    b7.Tag = "TOP";
                }
                else
                {
                    if (Convert.ToString(b7.Tag) == "TOP")
                    {
                        b7.Visible = false;
                        b7.Tag = "";
                    }
                    else
                    {
                        b7.Activate();
                        TagClear();
                        b7.Tag = "TOP";
                    }
                }
                //============================================
                //b7.Visible = !b7.Visible;
            }
            catch
            {
                b7 = new FrmAnalyzerList();
                b7.Show();
            }
            this.Cursor = Cursors.Default;

        }

        #endregion

        #region 視窗關閉縮小紐設定

        private void BtnClose_Click(object sender, EventArgs e)
        {
            checkPic = !checkPic;//解決關閉讀圖Bug
            Application.Exit();
        }

        private void BtnNarrow_Click(object sender, EventArgs e)
        {
            this.WindowState = FormWindowState.Minimized;
        }

        private void BtnClose_MouseMove(object sender, MouseEventArgs e)
        {
            this.BtnClose.BackgroundImage = imageList1.Images[1];
        }

        private void BtnClose_MouseLeave(object sender, EventArgs e)
        {
            if (checkPic)
            {
                this.BtnClose.BackgroundImage = imageList1.Images[0];
            }
        }

        private void BtnNarrow_MouseMove(object sender, MouseEventArgs e)
        {
            this.BtnNarrow.BackgroundImage = imageList1.Images[3];
        }

        private void BtnNarrow_MouseLeave(object sender, EventArgs e)
        {
            this.BtnNarrow.BackgroundImage = imageList1.Images[2];
        }

        #endregion

        


    }
}
